<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>不使用插件设置代理跨域</title>
</head>
<body>
<h2 style="text-align: center;">不使用插件设置代理跨域</h2>
<button>通过Proxy跨域</button>
<p>hello world！</p>

<script>
    var btn = document.getElementsByTagName('button')[0];
    var text = document.getElementsByTagName('p')[0];
    btn.addEventListener('click', function () {
        var xhr = new XMLHttpRequest();

        var proxy_url = 'http://localhost:3000/proxy?url=http://localhost:3001/'

        xhr.open('GET', proxy_url)
        xhr.send()
        xhr.onreadystatechange = () => {
            if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                console.log(xhr.response)
                text.innerHTML = xhr.response;
            }
        }
    })
</script>
</body>
</html>